package com.gusto.engine.spring.parsers;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
import com.gusto.engine.semsim.measures.impl.WordNetSimilarity;

public class ParserWordNetSimilarity extends AbstractBeanDefinitionParser {
	
	//@SuppressWarnings("unchecked")
	protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
		BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(WordNetSimilarity.class);
		
		if (element.hasAttribute("wordnetConfig")) {
			String wordnetConfig = element.getAttribute("wordnetConfig");
			beanDefinitionBuilder.addPropertyValue("PARAM_WORDNET_CONFIG", wordnetConfig);
		}
		if (element.hasAttribute("infocontent")) {
			String infocontent = element.getAttribute("infocontent");
			beanDefinitionBuilder.addPropertyValue("PARAM_INFOCONTENT", infocontent);
		}
		if (element.hasAttribute("mapping")) {
			String mapping = element.getAttribute("mapping");
			beanDefinitionBuilder.addPropertyValue("PARAM_MAPPING", mapping);
		}
		
		if (element.hasAttribute("firstWordOnly")) {
			String firstWordOnly = element.getAttribute("firstWordOnly");
			beanDefinitionBuilder.addPropertyValue("firstWordOnly", firstWordOnly);
		}
		return beanDefinitionBuilder.getBeanDefinition();
	}
}
